package ui.component
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.utils.Dictionary;
	
	import flashx.textLayout.formats.TextAlign;
	
	public class ContrastValue extends Sprite
	{
		private var _value:int;
		private var _nextValue:int;
		private var _title:TextField;
		private var _valueText:TextField;
		private var _contrastText:TextField
		private var _arrow:Bitmap;
		private var _upperData:BitmapData;
		private var _lowerData:BitmapData;
		
		/////////////////////////////////////////////
		public function get value():int
		{
			return _value;
		}

		public function set value(value:int):void
		{
			_value = value;
			
			_valueText.text = String(_value);
		}
		
		public function get nextValue():int
		{
			return _nextValue;
		}
		
		public function set nextValue(value:int):void
		{
			_nextValue = value;
			
			addChild(_arrow);
			
			if(_nextValue - _value != 0)
			{
				_contrastText.text =  String( _nextValue - _value);
				_arrow.x =  _title.textWidth + _valueText.textWidth+5;
				_contrastText.x = _arrow.x+9;
				
				if(_nextValue - _value>0)
				{
					_arrow.bitmapData = _upperData;
					_contrastText.textColor = 0x00ff00
				}
				else if (_nextValue - _value<0)
				{
					_arrow.bitmapData = _lowerData;
					_contrastText.textColor = 0xff0000;
				}
			}else
			{
				removeChild(_arrow);
				_contrastText.text = "";
			}
		}
		
		/////////////////////////////////////////////
		public function ContrastValue(Title:String,BitmapDatas:Dictionary)
		{
			_upperData = BitmapDatas["upper"];
			_lowerData = BitmapDatas["lower"];
			
			_title = new TextField;
			_valueText = new TextField;
			_contrastText = new TextField;
			
			_title.textColor = _valueText.textColor = 0xdddddd;
			
			var format:TextFormat = new TextFormat("SimHei");
			format.align = TextAlign.LEFT;
			format.size = 14;
			
			_title.defaultTextFormat = _valueText.defaultTextFormat = _contrastText.defaultTextFormat = format;
			
			_title.height = 20;
			_title.text = Title;
			_title.y = _valueText.y = _contrastText.y = 1;
			
			_arrow = new Bitmap();
			
			_valueText.x = _title.textWidth;
			_arrow.x =  _title.textWidth + _valueText.textWidth +5;
			_arrow.y = 5;
			_contrastText.x = _title.textWidth + _valueText.textWidth+30;
			
			addChild(_title);
			addChild(_valueText);
			addChild(_contrastText);
		}
		
	}
}